using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BO;
using BO.Admin;

namespace GUI.Controls.Detail
{
    public partial class NewsDetails : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }

        private void BindData()
        {
            if (Utils.QueryString.GetNewsID() > 0)
            {
                DataTable dtNews = News_Helper.GetByNewsID(Utils.QueryString.GetNewsID());
                if (dtNews != null && dtNews.Rows.Count > 0)
                {
                    Page.Title = dtNews.Rows[0]["News_Title"] != DBNull.Value ? (Server.HtmlEncode(dtNews.Rows[0]["News_Title"].ToString()) + PublicConstants.COMMON_TITLE) : PublicConstants.SINGLE_PAGE_TITLE;
                    ltrNewsTitle.Text = dtNews.Rows[0]["News_Title"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["News_Title"].ToString()) : String.Empty;
                    ltrPhoto.Text = dtNews.Rows[0]["Photo"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["Photo"].ToString()) : String.Empty;
                    phPhoto.Visible = dtNews.Rows[0]["Photo"] != DBNull.Value;
                    ltrStylist.Text = dtNews.Rows[0]["Stylist"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["Stylist"].ToString()) : String.Empty;
                    phStylist.Visible = dtNews.Rows[0]["Stylist"] != DBNull.Value;
                    ltrMakeup.Text = dtNews.Rows[0]["Makeup"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["Makeup"].ToString()) : String.Empty;
                    phMakeup.Visible = dtNews.Rows[0]["Makeup"] != DBNull.Value;
                    ltrModel.Text = dtNews.Rows[0]["Model"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["Model"].ToString()) : String.Empty;
                    phModel.Visible = dtNews.Rows[0]["Model"] != DBNull.Value;
                    ltrCostume.Text = dtNews.Rows[0]["Costume"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["Costume"].ToString()) : String.Empty;
                    phCostume.Visible = dtNews.Rows[0]["Costume"] != DBNull.Value;
                    ltrLocation.Text = dtNews.Rows[0]["Location"] != DBNull.Value ? Server.HtmlEncode(dtNews.Rows[0]["Location"].ToString()) : String.Empty;
                    phLocation.Visible = dtNews.Rows[0]["Location"] != DBNull.Value;
                }
                else Response.Redirect("/");
                DataTable dtSlider = Image_Helper.GetByNewsID(Utils.QueryString.GetNewsID());
                if (dtSlider != null && dtSlider.Rows.Count > 4)
                {
                    DataTable dtSlider1 = dtSlider.Clone();
                    for (int i = 0; i < 4; i++)
                    {
                        dtSlider1.ImportRow(dtSlider.Rows[i]);
                    }
                    rptSlider.DataSource = null;
                    rptSlider.DataSource = dtSlider1;
                    rptSlider.DataBind();
                    if (dtSlider.Rows.Count > 5)
                    {
                        DataTable dtSlider2 = dtSlider.Clone();
                        for (int i = 4; i < dtSlider.Rows.Count; i++)
                        {
                            dtSlider2.ImportRow(dtSlider.Rows[i]);
                        }
                        rptImagePreload.DataSource = null;
                        rptImagePreload.DataSource = dtSlider2;
                        rptImagePreload.DataBind();
                        rptLink.DataSource = null;
                        rptLink.DataSource = dtSlider2;
                        rptLink.DataBind();
                    }
                }
                else
                {
                    rptSlider.DataSource = null;
                    rptSlider.DataSource = dtSlider;
                    rptSlider.DataBind();
                }
            }
            else Response.Redirect("/");
        }
    }
}